/**
 */
package org.mro.grib.model.files.secondEdition.sections.impl;

import java.nio.ByteBuffer;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.mro.grib.model.files.secondEdition.sections.BitMapSection;
import org.mro.grib.model.files.secondEdition.sections.SectionsPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Bit Map Section</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.mro.grib.model.files.secondEdition.sections.impl.BitMapSectionImpl#getStartOffset <em>Start Offset</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.sections.impl.BitMapSectionImpl#getEndOffset <em>End Offset</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.sections.impl.BitMapSectionImpl#getLength <em>Length</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.sections.impl.BitMapSectionImpl#getBitMapIndicator <em>Bit Map Indicator</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.sections.impl.BitMapSectionImpl#getBitMapOffset <em>Bit Map Offset</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class BitMapSectionImpl extends EObjectImpl implements BitMapSection {
	/**
	 * The default value of the '{@link #getStartOffset() <em>Start Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long START_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getStartOffset() <em>Start Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartOffset()
	 * @generated
	 * @ordered
	 */
	protected long startOffset = START_OFFSET_EDEFAULT;

	/**
	 * The default value of the '{@link #getEndOffset() <em>End Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEndOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long END_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getEndOffset() <em>End Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEndOffset()
	 * @generated
	 * @ordered
	 */
	protected long endOffset = END_OFFSET_EDEFAULT;

	/**
	 * The default value of the '{@link #getLength() <em>Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLength()
	 * @generated
	 * @ordered
	 */
	protected static final int LENGTH_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getLength() <em>Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLength()
	 * @generated
	 * @ordered
	 */
	protected int length = LENGTH_EDEFAULT;

	/**
	 * The default value of the '{@link #getBitMapIndicator() <em>Bit Map Indicator</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBitMapIndicator()
	 * @generated
	 * @ordered
	 */
	protected static final byte BIT_MAP_INDICATOR_EDEFAULT = 0x00;

	/**
	 * The cached value of the '{@link #getBitMapIndicator() <em>Bit Map Indicator</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBitMapIndicator()
	 * @generated
	 * @ordered
	 */
	protected byte bitMapIndicator = BIT_MAP_INDICATOR_EDEFAULT;

	/**
	 * The default value of the '{@link #getBitMapOffset() <em>Bit Map Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBitMapOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long BIT_MAP_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getBitMapOffset() <em>Bit Map Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBitMapOffset()
	 * @generated
	 * @ordered
	 */
	protected long bitMapOffset = BIT_MAP_OFFSET_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BitMapSectionImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SectionsPackage.Literals.BIT_MAP_SECTION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getStartOffset() {
		return startOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStartOffset(long newStartOffset) {
		long oldStartOffset = startOffset;
		startOffset = newStartOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BIT_MAP_SECTION__START_OFFSET, oldStartOffset, startOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getEndOffset() {
		return endOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEndOffset(long newEndOffset) {
		long oldEndOffset = endOffset;
		endOffset = newEndOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BIT_MAP_SECTION__END_OFFSET, oldEndOffset, endOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getLength() {
		return length;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLength(int newLength) {
		int oldLength = length;
		length = newLength;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BIT_MAP_SECTION__LENGTH, oldLength, length));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public byte getBitMapIndicator() {
		return bitMapIndicator;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBitMapIndicator(byte newBitMapIndicator) {
		byte oldBitMapIndicator = bitMapIndicator;
		bitMapIndicator = newBitMapIndicator;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BIT_MAP_SECTION__BIT_MAP_INDICATOR, oldBitMapIndicator, bitMapIndicator));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getBitMapOffset() {
		return bitMapOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBitMapOffset(long newBitMapOffset) {
		long oldBitMapOffset = bitMapOffset;
		bitMapOffset = newBitMapOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BIT_MAP_SECTION__BIT_MAP_OFFSET, oldBitMapOffset, bitMapOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SectionsPackage.BIT_MAP_SECTION__START_OFFSET:
				return getStartOffset();
			case SectionsPackage.BIT_MAP_SECTION__END_OFFSET:
				return getEndOffset();
			case SectionsPackage.BIT_MAP_SECTION__LENGTH:
				return getLength();
			case SectionsPackage.BIT_MAP_SECTION__BIT_MAP_INDICATOR:
				return getBitMapIndicator();
			case SectionsPackage.BIT_MAP_SECTION__BIT_MAP_OFFSET:
				return getBitMapOffset();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SectionsPackage.BIT_MAP_SECTION__START_OFFSET:
				setStartOffset((Long)newValue);
				return;
			case SectionsPackage.BIT_MAP_SECTION__END_OFFSET:
				setEndOffset((Long)newValue);
				return;
			case SectionsPackage.BIT_MAP_SECTION__LENGTH:
				setLength((Integer)newValue);
				return;
			case SectionsPackage.BIT_MAP_SECTION__BIT_MAP_INDICATOR:
				setBitMapIndicator((Byte)newValue);
				return;
			case SectionsPackage.BIT_MAP_SECTION__BIT_MAP_OFFSET:
				setBitMapOffset((Long)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SectionsPackage.BIT_MAP_SECTION__START_OFFSET:
				setStartOffset(START_OFFSET_EDEFAULT);
				return;
			case SectionsPackage.BIT_MAP_SECTION__END_OFFSET:
				setEndOffset(END_OFFSET_EDEFAULT);
				return;
			case SectionsPackage.BIT_MAP_SECTION__LENGTH:
				setLength(LENGTH_EDEFAULT);
				return;
			case SectionsPackage.BIT_MAP_SECTION__BIT_MAP_INDICATOR:
				setBitMapIndicator(BIT_MAP_INDICATOR_EDEFAULT);
				return;
			case SectionsPackage.BIT_MAP_SECTION__BIT_MAP_OFFSET:
				setBitMapOffset(BIT_MAP_OFFSET_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SectionsPackage.BIT_MAP_SECTION__START_OFFSET:
				return startOffset != START_OFFSET_EDEFAULT;
			case SectionsPackage.BIT_MAP_SECTION__END_OFFSET:
				return endOffset != END_OFFSET_EDEFAULT;
			case SectionsPackage.BIT_MAP_SECTION__LENGTH:
				return length != LENGTH_EDEFAULT;
			case SectionsPackage.BIT_MAP_SECTION__BIT_MAP_INDICATOR:
				return bitMapIndicator != BIT_MAP_INDICATOR_EDEFAULT;
			case SectionsPackage.BIT_MAP_SECTION__BIT_MAP_OFFSET:
				return bitMapOffset != BIT_MAP_OFFSET_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (startOffset: "); //$NON-NLS-1$
		result.append(startOffset);
		result.append(", endOffset: "); //$NON-NLS-1$
		result.append(endOffset);
		result.append(", length: "); //$NON-NLS-1$
		result.append(length);
		result.append(", bitMapIndicator: "); //$NON-NLS-1$
		result.append(bitMapIndicator);
		result.append(", bitMapOffset: "); //$NON-NLS-1$
		result.append(bitMapOffset);
		result.append(')');
		return result.toString();
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.secondEdition.sections.BitMapSection#initialise(java.nio.ByteBuffer)
	 */
	@Override
	public void initialise(ByteBuffer buffer) {
		bitMapIndicator = buffer.get();
		bitMapOffset = startOffset + (Integer.SIZE + Byte.SIZE) / Byte.SIZE;
	}

} //BitMapSectionImpl
